var ns,  app,toast;
app = new Vue({
    el: '#app',
    data: {
        form: {
            PrijectID:0,
            BuildingID:0,
            PrijectIDName:'',
            PlanTask:0,//巡查任务数
            decoration:0,//装修中数量
            Status:2,//1--申请中。2--装修中，3--拒绝，4--已完成，5--已结算
        },
        isactive:true,
        dateTime:'',

    },
    methods: {
        getData:function(){
            var that=this;
            var options = {};
            options.PrijectID = that.form.PrijectID;
            options.BuildingID = that.form.BuildingID;
            options.action = "getdecorationmanagementkanban";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.form = data;
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })
        

        },
        //选择楼栋
        choose_loudong:function(item){
            var that=this;
            if(item==0){
                that.isactive=!that.isactive;
                that.form.BuildingID=0;
                that.getData();
            }else{
                var loudonglist=that.form.items;
                for (var i = 0; i <loudonglist.length; i++) {
                    loudonglist[i].iszctive = false;
                }
                item.iszctive=true;
                that.form.BuildingID=item.id;
                new Promise(function (resolve, reject) {
                        that.getData();
                        resolve();
                }).then(function () {
                    setTimeout(function () {
                        that.isactive=false;
                    }, 500);
                });




                // that.getData();
                // setTimeout(() => {
                //     that.isactive=false;
                // }, 1000);
                
            }
            
        },

        choosexiaoqu:function(){
            var that=this;
            ns.openWin('zx_xiaoqu', '切换小区');
        },
        // doCloseRoom:function(){

        // },
        do_openrenwu_list:function(){
            var that=this;

            ns.openWin('zxrenwu_list_frm', '装修任务列表',{
                PrijectID:that.form.PrijectID//项目id
            });
        },
        do_open_zxdetail:function(id,IsStop){
            var that=this;
            var IsRoomOpenid=0;
            if(IsStop==false){
                IsRoomOpenid=0
            }
            if(IsStop==true){
                IsRoomOpenid=1
            }
           
            ns.openWin('zxrenwu_detail_frm', '装修详情',{
                ID:id,
                IsRoomOpenid:IsRoomOpenid
            });
        }


    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    toast = new auiToast();
    //初始化时间
    var data = new Date();
    var year = data.getFullYear();
    var month = data.getMonth() + 1;
    var day=data.getDate();
    app.dateTime = year + '年' + (month >= 10 ? month : '0' + month)+'月'+(day >= 10 ? day : '0' + day)+'日';
    api.addEventListener({
        name: 'selected_xiaoqu'
    }, function (ret) {
        app.form.PrijectID=ret.value.xiaoquid;
        app.form.PrijectIDName=ret.value.xiaoquname;
        app.isactive=true;
        app.getData();
    });
    app.getData();
    api.addEventListener({
        name: 'isStop'
    }, function () {
        app.getData();
    });
    api.addEventListener({
        name: 'xuncha_updata'
    }, function () {
        app.getData();
    });
    api.addEventListener({
        name: 'chayan_updata'
    }, function () {
        app.getData();
    });
    api.addEventListener({
        name: 'zhuanjiao_updata'
    }, function () {
        app.getData();
    });

};
